﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufStandaloneArrangementArea.h"

namespace gnuf {

    class Adjoinment;
    class FloatingArrangementArea;
    class IsolatedArrangementArea;
    
    class DesktopArrangementArea final : public StandaloneArrangementArea
    {
        CANNOT_COPY_OR_ASSIGN(DesktopArrangementArea)
    public:
        DesktopArrangementArea();
        ~DesktopArrangementArea();

        void setOperative(bool);
        bool isOperative() const { return m_operative; }
        
        inline void setLayoutConfigration(const std::string & version)
        {
            m_layoutConfigrationVersion = version;
        }
        inline const std::string & layoutConfigrationVersion() const {
            return m_layoutConfigrationVersion;
        }

        void addAdjoinment(ArrangementArea *, ArrangementArea *, bool);
        Adjoinment * findAdjoinment(int x, int y);
        void removeAdjoinmentsRelatedTo(const ArrangementArea *);

        void setFloating(ArrangementArea *);
        bool isFloating(const ArrangementArea *) const;
        void dock(ArrangementArea *, const DockingArrangementArea *);
        void dockAllArrangementAreas();

        IsolatedArrangementArea * addIsolatedArrangementArea();
        void removeIsolatedArrangementArea(const IsolatedArrangementArea *);
        void closeAllIsolatedArrangementAreas(bool wantToRetrieveBeforeClose = false);
        typedef std::list< gcmp::OwnerPtr< IsolatedArrangementArea > > IsolatedArrangementAreas;
        const DesktopArrangementArea::IsolatedArrangementAreas & isolatedArrangementAreas() const {
            return m_isolatedArrangementAreas;
        }

        void travelAllSubStandaloneArrangementAreas(const std::function<bool(StandaloneArrangementArea *)> &);
        
    protected:
        // Inherits from ArrangementArea...
        virtual void onPreLayoutRefreshed() override;
        virtual void onPostLayoutRefreshed() override;

        // Inherits from IQtMaskHandler...
        virtual bool onIsMasked(const QtMask * const, const std::uint64_t, bool) override;
        
    private:
        void traverseIsolatedArrangementAreas(const std::function<void(IsolatedArrangementArea *)> &);

        bool m_operative;
        std::string m_layoutConfigrationVersion;
        typedef std::list< gcmp::OwnerPtr< Adjoinment > > Adjoinments;
        DesktopArrangementArea::Adjoinments m_adjoinments;
        typedef std::list< gcmp::OwnerPtr< FloatingArrangementArea > > FloatingArrangementAreas;
        DesktopArrangementArea::FloatingArrangementAreas m_floatingArrangementAreas;
        typedef std::list< gcmp::OwnerPtr< IsolatedArrangementArea > > IsolatedArrangementAreas;
        DesktopArrangementArea::IsolatedArrangementAreas m_isolatedArrangementAreas;
    };

}
